unit MainCtrl;

interface
uses
  SysUtils, windows, forms, buttons, classes, Menus, controls, patterns,
  MainView, toolbox, commandlist;

type
  TControllerMain = class(TController)
    view: TViewMain;
  protected
    procedure DoCommand(Command: string; const args: string=''); override;
  public
    constructor Create;
    procedure OnClick(Sender: TObject); //for ieventListener
    procedure OnMouseEvent(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  end;

implementation

procedure TControllerMain.OnClick(Sender: TObject);
begin
  if (Sender is TMenuItem) then
  begin
    if TMenuItem(Sender).Caption = CMD_FILE_EXIT then
      view.Close
    else if TMenuItem(Sender).Caption = CMD_SHOW_HELP then
      Application.HelpCommand(HELP_CONTENTS, 0)
    else
      self.SendCommand(TMenuItem(Sender).Caption);
  end
  else if (Sender is TSpeedButton) then
  begin
    if TSpeedButton(Sender).Caption = CMD_BTN_CLOSE then
      view.Close
    else if TSpeedButton(Sender).Caption = CMD_BTN_HELP then
      Application.HelpCommand(HELP_CONTENTS, 0)
    else
      self.SendCommand(TSpeedButton(Sender).Caption);
  end;
end;

procedure TControllerMain.OnMouseEvent(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin

end;

constructor TControllerMain.Create;
begin
  inherited;
  Application.CreateForm(TViewMain, view);
  view.setEventListener(self.OnClick);
end;


procedure TControllerMain.DoCommand(Command: string; const args: string='');
begin
  if Command = CMD_SYSTEM_START then
    view.Show;
end;

initialization
  ControlCenter.RegController(TControllerMain.Create);

end.

